/**
 * @file cfgym/103389/a/main.cpp
 * @brief
 * @see
 * @author Ruiming Guo (guoruiming@stu.scu.edu.cn)
 * @copyright 2022
 * @date 2022/5/15 13:11:29
 **/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int N = 40;
int n, m;
vi company[N];
vi adj[N];
int companyMoney[N];
int c[N];
int select[N];
int rec[N];
int dp[N];
bool getnext() {
  int carry = 1;
  for (int i = n; i >= 1; --i) {
    select[i] += carry;
    if (select[i] >= company[i].size()) {
      carry = true;
      select[i] = 0;
    } else
      carry = false;
  }
  return !carry;
}
int main() {
  // High rating and good luck!
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> c[i];
    company[c[i]].push_back(i);
  }
  for (int i = 1; i <= n; ++i) cin >> companyMoney[i];
  for (int i = 1; i <= m; ++i) {
    int u, v;
    cin >> u >> v;
    adj[v].push_back(u);  // reverse
  }

  do {
    memset(dp, 0, sizeof(dp));
    bool mask[N] = {0};
    for (int i = 1; i <= n; ++i) {
      if (company[i].size()) mask[company[i][select[i]]] = true;
    }

    for (int i = 1; i <= n; ++i) {
      int val = 0;
      for (auto u : adj[i]) {
        val = max(val, dp[u]);
      }
      dp[i] = val + (mask[i] ? companyMoney[c[i]] : 0);
    }
    for (int i = 1; i <= n; ++i) rec[i] = max(rec[i], dp[i]);

  } while (getnext());
  for (int i = 1; i <= n; ++i) cout << rec[i] << endl;
  return 0;
}
